package com.dianda.controller;

import com.dianda.pojo.*;
import com.dianda.service.ClassmateService;
import com.dianda.service.FoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class FoodsController {

    @Autowired
    FoodsService service;

    @PostMapping("/app13/food/list")
    public FoodsResult getFoodsList() {
        List<Foods> list = service.getFoodsList();
        FoodsResult r = new FoodsResult();
        if (list != null) {
            r.setSuccess(true);
            r.setMsg("成功");
            r.setList(list);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }
    @PostMapping("/app14/food/findone")
    public FoodsResult findone(@RequestBody Foods foods){
        Integer id = foods.getId();
        FoodsResult r = new FoodsResult();
        Foods foods1 = service.findById(id);
        if (foods1!=null){
            r.setSuccess(true);
            r.setMsg("成功");
            r.setData(foods1);
        }else{
            r.setSuccess(false);
            r.setMsg("失败");
        }
        return r;
    }

}
